.class public Lcom/snowplowanalytics/snowplow/tracker/Emitter;
.super Ljava/lang/Object;


# static fields
.field private static final POST_STM_BYTES:I = 0x16

.field private static final POST_WRAPPER_BYTES:I = 0x58


# instance fields
.field private final JSON:Lokhttp3/MediaType;

.field private final TAG:Ljava/lang/String;

.field private bufferOption:Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;

.field private byteLimitGet:J

.field private byteLimitPost:J

.field private final client:Lokhttp3/OkHttpClient;

.field private context:Landroid/content/Context;

.field private emitterTick:I

.field private emptyCount:I

.field private emptyLimit:I

.field private eventStore:Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;

.field private httpMethod:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

.field private isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

.field private requestCallback:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;

.field private requestSecurity:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;

.field private sendLimit:I

.field private timeUnit:Ljava/util/concurrent/TimeUnit;

.field private uri:Ljava/lang/String;

.field private uriBuilder:Landroid/net/Uri$Builder;


# direct methods
.method private constructor <init>(Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;)V
    .locals 6

    const-wide/16 v4, 0xf

    const/4 v3, 0x0

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    const-class v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;

    invoke-virtual {v0}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v0, "application/json; charset=utf-8"

    invoke-static {v0}, Lokhttp3/MediaType;->parse(Ljava/lang/String;)Lokhttp3/MediaType;

    move-result-object v0

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->JSON:Lokhttp3/MediaType;

    new-instance v0, Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-direct {v0, v3}, Ljava/util/concurrent/atomic/AtomicBoolean;-><init>(Z)V

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    iget-object v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->httpMethod:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->httpMethod:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

    iget-object v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->requestCallback:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestCallback:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;

    iget-object v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->context:Landroid/content/Context;

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->context:Landroid/content/Context;

    iget-object v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->bufferOption:Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->bufferOption:Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;

    iget-object v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->requestSecurity:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestSecurity:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;

    iget v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->emitterTick:I

    iput v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emitterTick:I

    iget v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->emptyLimit:I

    iput v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emptyLimit:I

    iget v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->sendLimit:I

    iput v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->sendLimit:I

    iget-wide v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->byteLimitGet:J

    iput-wide v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->byteLimitGet:J

    iget-wide v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->byteLimitPost:J

    iput-wide v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->byteLimitPost:J

    iget-object v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->uri:Ljava/lang/String;

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uri:Ljava/lang/String;

    iget-object v0, p1, Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;->timeUnit:Ljava/util/concurrent/TimeUnit;

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->timeUnit:Ljava/util/concurrent/TimeUnit;

    new-instance v0, Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;

    iget-object v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->context:Landroid/content/Context;

    iget v2, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->sendLimit:I

    invoke-direct {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;-><init>(Landroid/content/Context;I)V

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->eventStore:Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;

    invoke-direct {p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->buildEmitterUri()V

    new-instance v0, Lokhttp3/OkHttpClient$Builder;

    invoke-direct {v0}, Lokhttp3/OkHttpClient$Builder;-><init>()V

    sget-object v1, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;

    invoke-virtual {v0, v4, v5, v1}, Lokhttp3/OkHttpClient$Builder;->connectTimeout(JLjava/util/concurrent/TimeUnit;)Lokhttp3/OkHttpClient$Builder;

    move-result-object v0

    sget-object v1, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;

    invoke-virtual {v0, v4, v5, v1}, Lokhttp3/OkHttpClient$Builder;->readTimeout(JLjava/util/concurrent/TimeUnit;)Lokhttp3/OkHttpClient$Builder;

    move-result-object v0

    invoke-virtual {v0}, Lokhttp3/OkHttpClient$Builder;->build()Lokhttp3/OkHttpClient;

    move-result-object v0

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->client:Lokhttp3/OkHttpClient;

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Emitter created successfully!"

    new-array v2, v3, [Ljava/lang/Object;

    invoke-static {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->v(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    return-void
.end method

.method synthetic constructor <init>(Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;Lcom/snowplowanalytics/snowplow/tracker/Emitter$1;)V
    .locals 0

    invoke-direct {p0, p1}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;-><init>(Lcom/snowplowanalytics/snowplow/tracker/Emitter$EmitterBuilder;)V

    return-void
.end method

.method static synthetic access$100(Lcom/snowplowanalytics/snowplow/tracker/Emitter;)Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->eventStore:Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;

    return-object v0
.end method

.method static synthetic access$200(Lcom/snowplowanalytics/snowplow/tracker/Emitter;)Ljava/util/concurrent/atomic/AtomicBoolean;
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    return-object v0
.end method

.method static synthetic access$300(Lcom/snowplowanalytics/snowplow/tracker/Emitter;)V
    .locals 0

    invoke-direct {p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->attemptEmit()V

    return-void
.end method

.method static synthetic access$400(Lcom/snowplowanalytics/snowplow/tracker/Emitter;Lokhttp3/Request;)I
    .locals 1

    invoke-direct {p0, p1}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestSender(Lokhttp3/Request;)I

    move-result v0

    return v0
.end method

.method private addStmToEvent(Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;Ljava/lang/String;)V
    .locals 2

    const-string v0, "stm"

    const-string v1, ""

    invoke-virtual {p2, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_0

    invoke-static {}, Lcom/snowplowanalytics/snowplow/tracker/utils/Util;->getTimestamp()Ljava/lang/String;

    move-result-object p2

    :cond_0
    invoke-interface {p1, v0, p2}, Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;->add(Ljava/lang/String;Ljava/lang/String;)V

    return-void
.end method

.method private attemptEmit()V
    .locals 9

    const/4 v8, 0x1

    const/4 v3, 0x0

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->context:Landroid/content/Context;

    invoke-static {v0}, Lcom/snowplowanalytics/snowplow/tracker/utils/Util;->isOnline(Landroid/content/Context;)Z

    move-result v0

    if-eqz v0, :cond_9

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->eventStore:Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;->getSize()J

    move-result-wide v0

    const-wide/16 v4, 0x0

    cmp-long v0, v0, v4

    if-lez v0, :cond_7

    iput v3, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emptyCount:I

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->eventStore:Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;->getEmittableEvents()Lcom/snowplowanalytics/snowplow/tracker/emitter/EmittableEvents;

    move-result-object v0

    invoke-virtual {p0, v0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->buildRequests(Lcom/snowplowanalytics/snowplow/tracker/emitter/EmittableEvents;)Ljava/util/LinkedList;

    move-result-object v0

    invoke-virtual {p0, v0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->performAsyncEmit(Ljava/util/LinkedList;)Ljava/util/LinkedList;

    move-result-object v0

    iget-object v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v2, "Processing emitter results."

    new-array v4, v3, [Ljava/lang/Object;

    invoke-static {v1, v2, v4}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->v(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    new-instance v5, Ljava/util/LinkedList;

    invoke-direct {v5}, Ljava/util/LinkedList;-><init>()V

    invoke-virtual {v0}, Ljava/util/LinkedList;->iterator()Ljava/util/Iterator;

    move-result-object v6

    move v2, v3

    move v4, v3

    :goto_0
    invoke-interface {v6}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_2

    invoke-interface {v6}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;->getSuccess()Z

    move-result v1

    if-eqz v1, :cond_1

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;->getEventIds()Ljava/util/LinkedList;

    move-result-object v1

    invoke-virtual {v1}, Ljava/util/LinkedList;->iterator()Ljava/util/Iterator;

    move-result-object v7

    :goto_1
    invoke-interface {v7}, Ljava/util/Iterator;->hasNext()Z

    move-result v1

    if-eqz v1, :cond_0

    invoke-interface {v7}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/Long;

    invoke-virtual {v5, v1}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    goto :goto_1

    :cond_0
    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;->getEventIds()Ljava/util/LinkedList;

    move-result-object v0

    invoke-virtual {v0}, Ljava/util/LinkedList;->size()I

    move-result v0

    add-int v1, v4, v0

    move v0, v2

    :goto_2
    move v2, v0

    move v4, v1

    goto :goto_0

    :cond_1
    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;->getEventIds()Ljava/util/LinkedList;

    move-result-object v0

    invoke-virtual {v0}, Ljava/util/LinkedList;->size()I

    move-result v0

    add-int/2addr v0, v2

    iget-object v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v2, "Request sending failed but we will retry later."

    new-array v7, v3, [Ljava/lang/Object;

    invoke-static {v1, v2, v7}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    move v1, v4

    goto :goto_2

    :cond_2
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->eventStore:Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;

    invoke-virtual {v0, v5}, Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;->removeEvents(Ljava/util/List;)Z

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Success Count: %s"

    new-array v5, v8, [Ljava/lang/Object;

    invoke-static {v4}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v6

    aput-object v6, v5, v3

    invoke-static {v0, v1, v5}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->d(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Failure Count: %s"

    new-array v5, v8, [Ljava/lang/Object;

    invoke-static {v2}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v6

    aput-object v6, v5, v3

    invoke-static {v0, v1, v5}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->d(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestCallback:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;

    if-eqz v0, :cond_3

    if-eqz v2, :cond_5

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestCallback:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;

    invoke-interface {v0, v4, v2}, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;->onFailure(II)V

    :cond_3
    :goto_3
    if-lez v2, :cond_6

    if-nez v4, :cond_6

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->context:Landroid/content/Context;

    invoke-static {v0}, Lcom/snowplowanalytics/snowplow/tracker/utils/Util;->isOnline(Landroid/content/Context;)Z

    move-result v0

    if-eqz v0, :cond_4

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Ensure collector path is valid: %s"

    new-array v2, v8, [Ljava/lang/Object;

    invoke-virtual {p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->getEmitterUri()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    invoke-static {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    :cond_4
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Emitter loop stopping: failures."

    new-array v2, v3, [Ljava/lang/Object;

    invoke-static {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0, v8, v3}, Ljava/util/concurrent/atomic/AtomicBoolean;->compareAndSet(ZZ)Z

    :goto_4
    return-void

    :cond_5
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestCallback:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;

    invoke-interface {v0, v4}, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;->onSuccess(I)V

    goto :goto_3

    :cond_6
    invoke-direct {p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->attemptEmit()V

    goto :goto_4

    :cond_7
    iget v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emptyCount:I

    iget v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emptyLimit:I

    if-lt v0, v1, :cond_8

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Emitter loop stopping: empty limit reached."

    new-array v2, v3, [Ljava/lang/Object;

    invoke-static {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0, v8, v3}, Ljava/util/concurrent/atomic/AtomicBoolean;->compareAndSet(ZZ)Z

    goto :goto_4

    :cond_8
    iget v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emptyCount:I

    add-int/lit8 v0, v0, 0x1

    iput v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emptyCount:I

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "Emitter database empty: "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    iget v2, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emptyCount:I

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    new-array v2, v3, [Ljava/lang/Object;

    invoke-static {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    :try_start_0
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->timeUnit:Ljava/util/concurrent/TimeUnit;

    iget v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emitterTick:I

    int-to-long v4, v1

    invoke-virtual {v0, v4, v5}, Ljava/util/concurrent/TimeUnit;->sleep(J)V
    :try_end_0
    .catch Ljava/lang/InterruptedException; {:try_start_0 .. :try_end_0} :catch_0

    :goto_5
    invoke-direct {p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->attemptEmit()V

    goto :goto_4

    :catch_0
    move-exception v0

    iget-object v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v4, "Emitter thread sleep interrupted: "

    invoke-virtual {v2, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v0}, Ljava/lang/InterruptedException;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    new-array v2, v3, [Ljava/lang/Object;

    invoke-static {v1, v0, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    goto :goto_5

    :cond_9
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Emitter loop stopping: emitter offline."

    new-array v2, v3, [Ljava/lang/Object;

    invoke-static {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0, v8, v3}, Ljava/util/concurrent/atomic/AtomicBoolean;->compareAndSet(ZZ)Z

    goto :goto_4
.end method

.method private buildEmitterUri()V
    .locals 2

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestSecurity:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;

    sget-object v1, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;->HTTP:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;

    if-ne v0, v1, :cond_0

    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    const-string v1, "http://"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    iget-object v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uri:Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v0

    invoke-virtual {v0}, Landroid/net/Uri;->buildUpon()Landroid/net/Uri$Builder;

    move-result-object v0

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    :goto_0
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->httpMethod:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

    sget-object v1, Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;->GET:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

    if-ne v0, v1, :cond_1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    const-string v1, "i"

    invoke-virtual {v0, v1}, Landroid/net/Uri$Builder;->appendPath(Ljava/lang/String;)Landroid/net/Uri$Builder;

    :goto_1
    return-void

    :cond_0
    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    const-string v1, "https://"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    iget-object v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uri:Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v0

    invoke-virtual {v0}, Landroid/net/Uri;->buildUpon()Landroid/net/Uri$Builder;

    move-result-object v0

    iput-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    goto :goto_0

    :cond_1
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    const-string v1, "com.snowplowanalytics.snowplow/tp2"

    invoke-virtual {v0, v1}, Landroid/net/Uri$Builder;->appendEncodedPath(Ljava/lang/String;)Landroid/net/Uri$Builder;

    goto :goto_1
.end method

.method private getRequestCallable(Lokhttp3/Request;)Ljava/util/concurrent/Callable;
    .locals 1

    new-instance v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter$3;

    invoke-direct {v0, p0, p1}, Lcom/snowplowanalytics/snowplow/tracker/Emitter$3;-><init>(Lcom/snowplowanalytics/snowplow/tracker/Emitter;Lokhttp3/Request;)V

    return-object v0
.end method

.method private isSuccessfulSend(I)Z
    .locals 1

    const/16 v0, 0xc8

    if-lt p1, v0, :cond_0

    const/16 v0, 0x12c

    if-ge p1, v0, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method private requestBuilderGet(Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;)Lokhttp3/Request;
    .locals 5

    const-string v0, ""

    invoke-direct {p0, p1, v0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->addStmToEvent(Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;Ljava/lang/String;)V

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    invoke-virtual {v0}, Landroid/net/Uri$Builder;->clearQuery()Landroid/net/Uri$Builder;

    invoke-interface {p1}, Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;->getMap()Ljava/util/Map;

    move-result-object v0

    check-cast v0, Ljava/util/HashMap;

    invoke-virtual {v0}, Ljava/util/HashMap;->keySet()Ljava/util/Set;

    move-result-object v1

    invoke-interface {v1}, Ljava/lang/Iterable;->iterator()Ljava/util/Iterator;

    move-result-object v3

    :goto_0
    invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z

    move-result v1

    if-eqz v1, :cond_0

    invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/util/HashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/String;

    iget-object v4, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    invoke-virtual {v4, v1, v2}, Landroid/net/Uri$Builder;->appendQueryParameter(Ljava/lang/String;Ljava/lang/String;)Landroid/net/Uri$Builder;

    goto :goto_0

    :cond_0
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    invoke-virtual {v0}, Landroid/net/Uri$Builder;->build()Landroid/net/Uri;

    move-result-object v0

    invoke-virtual {v0}, Landroid/net/Uri;->toString()Ljava/lang/String;

    move-result-object v0

    new-instance v1, Lokhttp3/Request$Builder;

    invoke-direct {v1}, Lokhttp3/Request$Builder;-><init>()V

    invoke-virtual {v1, v0}, Lokhttp3/Request$Builder;->url(Ljava/lang/String;)Lokhttp3/Request$Builder;

    move-result-object v0

    invoke-virtual {v0}, Lokhttp3/Request$Builder;->get()Lokhttp3/Request$Builder;

    move-result-object v0

    invoke-virtual {v0}, Lokhttp3/Request$Builder;->build()Lokhttp3/Request;

    move-result-object v0

    return-object v0
.end method

.method private requestBuilderPost(Ljava/util/ArrayList;)Lokhttp3/Request;
    .locals 4

    new-instance v1, Ljava/util/ArrayList;

    invoke-direct {v1}, Ljava/util/ArrayList;-><init>()V

    invoke-static {}, Lcom/snowplowanalytics/snowplow/tracker/utils/Util;->getTimestamp()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {p1}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v3

    :goto_0
    invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_0

    invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;

    invoke-direct {p0, v0, v2}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->addStmToEvent(Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;Ljava/lang/String;)V

    invoke-interface {v0}, Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;->getMap()Ljava/util/Map;

    move-result-object v0

    invoke-virtual {v1, v0}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

    goto :goto_0

    :cond_0
    new-instance v0, Lcom/snowplowanalytics/snowplow/tracker/payload/SelfDescribingJson;

    const-string v2, "iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4"

    invoke-direct {v0, v2, v1}, Lcom/snowplowanalytics/snowplow/tracker/payload/SelfDescribingJson;-><init>(Ljava/lang/String;Ljava/lang/Object;)V

    iget-object v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    invoke-virtual {v1}, Landroid/net/Uri$Builder;->build()Landroid/net/Uri;

    move-result-object v1

    invoke-virtual {v1}, Landroid/net/Uri;->toString()Ljava/lang/String;

    move-result-object v1

    iget-object v2, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->JSON:Lokhttp3/MediaType;

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/payload/SelfDescribingJson;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {v2, v0}, Lokhttp3/RequestBody;->create(Lokhttp3/MediaType;Ljava/lang/String;)Lokhttp3/RequestBody;

    move-result-object v0

    new-instance v2, Lokhttp3/Request$Builder;

    invoke-direct {v2}, Lokhttp3/Request$Builder;-><init>()V

    invoke-virtual {v2, v1}, Lokhttp3/Request$Builder;->url(Ljava/lang/String;)Lokhttp3/Request$Builder;

    move-result-object v1

    invoke-virtual {v1, v0}, Lokhttp3/Request$Builder;->post(Lokhttp3/RequestBody;)Lokhttp3/Request$Builder;

    move-result-object v0

    invoke-virtual {v0}, Lokhttp3/Request$Builder;->build()Lokhttp3/Request;

    move-result-object v0

    return-object v0
.end method

.method private requestSender(Lokhttp3/Request;)I
    .locals 6

    const/4 v5, 0x1

    const/4 v4, 0x0

    :try_start_0
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Sending request: %s"

    const/4 v2, 0x1

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    aput-object p1, v2, v3

    invoke-static {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->v(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->client:Lokhttp3/OkHttpClient;

    invoke-virtual {v0, p1}, Lokhttp3/OkHttpClient;->newCall(Lokhttp3/Request;)Lokhttp3/Call;

    move-result-object v0

    invoke-interface {v0}, Lokhttp3/Call;->execute()Lokhttp3/Response;

    move-result-object v1

    invoke-virtual {v1}, Lokhttp3/Response;->code()I

    move-result v0

    invoke-virtual {v1}, Lokhttp3/Response;->body()Lokhttp3/ResponseBody;

    move-result-object v1

    invoke-virtual {v1}, Lokhttp3/ResponseBody;->close()V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    return v0

    :catch_0
    move-exception v0

    iget-object v1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v2, "Request sending failed: %s"

    new-array v3, v5, [Ljava/lang/Object;

    invoke-virtual {v0}, Ljava/io/IOException;->toString()Ljava/lang/String;

    move-result-object v0

    aput-object v0, v3, v4

    invoke-static {v1, v2, v3}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    const/4 v0, -0x1

    goto :goto_0
.end method


# virtual methods
.method public add(Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;)V
    .locals 1

    new-instance v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter$1;

    invoke-direct {v0, p0, p1}, Lcom/snowplowanalytics/snowplow/tracker/Emitter$1;-><init>(Lcom/snowplowanalytics/snowplow/tracker/Emitter;Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;)V

    invoke-static {v0}, Lcom/snowplowanalytics/snowplow/tracker/Executor;->execute(Ljava/lang/Runnable;)V

    return-void
.end method

.method protected buildRequests(Lcom/snowplowanalytics/snowplow/tracker/emitter/EmittableEvents;)Ljava/util/LinkedList;
    .locals 18

    invoke-virtual/range {p1 .. p1}, Lcom/snowplowanalytics/snowplow/tracker/emitter/EmittableEvents;->getEvents()Ljava/util/ArrayList;

    move-result-object v2

    invoke-virtual {v2}, Ljava/util/ArrayList;->size()I

    move-result v9

    invoke-virtual/range {p1 .. p1}, Lcom/snowplowanalytics/snowplow/tracker/emitter/EmittableEvents;->getEventIds()Ljava/util/LinkedList;

    move-result-object v12

    new-instance v13, Ljava/util/LinkedList;

    invoke-direct {v13}, Ljava/util/LinkedList;-><init>()V

    move-object/from16 v0, p0

    iget-object v2, v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->httpMethod:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

    sget-object v3, Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;->GET:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

    if-ne v2, v3, :cond_1

    const/4 v2, 0x0

    move v4, v2

    :goto_0
    if-ge v4, v9, :cond_6

    new-instance v5, Ljava/util/LinkedList;

    invoke-direct {v5}, Ljava/util/LinkedList;-><init>()V

    invoke-virtual {v12, v4}, Ljava/util/LinkedList;->get(I)Ljava/lang/Object;

    move-result-object v2

    invoke-virtual {v5, v2}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    invoke-virtual/range {p1 .. p1}, Lcom/snowplowanalytics/snowplow/tracker/emitter/EmittableEvents;->getEvents()Ljava/util/ArrayList;

    move-result-object v2

    invoke-virtual {v2, v4}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;

    invoke-interface {v2}, Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;->getByteSize()J

    move-result-wide v6

    const-wide/16 v10, 0x16

    add-long/2addr v6, v10

    move-object/from16 v0, p0

    iget-wide v10, v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->byteLimitGet:J

    cmp-long v3, v6, v10

    if-lez v3, :cond_0

    const/4 v3, 0x1

    :goto_1
    move-object/from16 v0, p0

    invoke-direct {v0, v2}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestBuilderGet(Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;)Lokhttp3/Request;

    move-result-object v2

    new-instance v6, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;

    invoke-direct {v6, v3, v2, v5}, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;-><init>(ZLokhttp3/Request;Ljava/util/LinkedList;)V

    invoke-virtual {v13, v6}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    add-int/lit8 v2, v4, 0x1

    move v4, v2

    goto :goto_0

    :cond_0
    const/4 v3, 0x0

    goto :goto_1

    :cond_1
    const/4 v4, 0x0

    :goto_2
    if-ge v4, v9, :cond_6

    new-instance v6, Ljava/util/LinkedList;

    invoke-direct {v6}, Ljava/util/LinkedList;-><init>()V

    new-instance v5, Ljava/util/ArrayList;

    invoke-direct {v5}, Ljava/util/ArrayList;-><init>()V

    const-wide/16 v2, 0x0

    move-object v8, v6

    move-wide v6, v2

    move v3, v4

    :goto_3
    move-object/from16 v0, p0

    iget-object v2, v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->bufferOption:Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;

    invoke-virtual {v2}, Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;->getCode()I

    move-result v2

    add-int/2addr v2, v4

    if-ge v3, v2, :cond_4

    if-ge v3, v9, :cond_4

    invoke-virtual/range {p1 .. p1}, Lcom/snowplowanalytics/snowplow/tracker/emitter/EmittableEvents;->getEvents()Ljava/util/ArrayList;

    move-result-object v2

    invoke-virtual {v2, v3}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;

    invoke-interface {v2}, Lcom/snowplowanalytics/snowplow/tracker/payload/Payload;->getByteSize()J

    move-result-wide v10

    const-wide/16 v14, 0x16

    add-long/2addr v10, v14

    const-wide/16 v14, 0x58

    add-long/2addr v14, v10

    move-object/from16 v0, p0

    iget-wide v0, v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->byteLimitPost:J

    move-wide/from16 v16, v0

    cmp-long v14, v14, v16

    if-lez v14, :cond_2

    new-instance v10, Ljava/util/ArrayList;

    invoke-direct {v10}, Ljava/util/ArrayList;-><init>()V

    new-instance v11, Ljava/util/LinkedList;

    invoke-direct {v11}, Ljava/util/LinkedList;-><init>()V

    invoke-virtual {v10, v2}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

    invoke-virtual {v12, v3}, Ljava/util/LinkedList;->get(I)Ljava/lang/Object;

    move-result-object v2

    invoke-virtual {v11, v2}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    move-object/from16 v0, p0

    invoke-direct {v0, v10}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestBuilderPost(Ljava/util/ArrayList;)Lokhttp3/Request;

    move-result-object v2

    new-instance v10, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;

    const/4 v14, 0x1

    invoke-direct {v10, v14, v2, v11}, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;-><init>(ZLokhttp3/Request;Ljava/util/LinkedList;)V

    invoke-virtual {v13, v10}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    :goto_4
    add-int/lit8 v2, v3, 0x1

    move v3, v2

    goto :goto_3

    :cond_2
    add-long v14, v6, v10

    const-wide/16 v16, 0x58

    add-long v14, v14, v16

    invoke-virtual {v5}, Ljava/util/ArrayList;->size()I

    move-result v16

    add-int/lit8 v16, v16, -0x1

    move/from16 v0, v16

    int-to-long v0, v0

    move-wide/from16 v16, v0

    add-long v14, v14, v16

    move-object/from16 v0, p0

    iget-wide v0, v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->byteLimitPost:J

    move-wide/from16 v16, v0

    cmp-long v14, v14, v16

    if-lez v14, :cond_3

    move-object/from16 v0, p0

    invoke-direct {v0, v5}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestBuilderPost(Ljava/util/ArrayList;)Lokhttp3/Request;

    move-result-object v5

    new-instance v6, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;

    const/4 v7, 0x0

    invoke-direct {v6, v7, v5, v8}, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;-><init>(ZLokhttp3/Request;Ljava/util/LinkedList;)V

    invoke-virtual {v13, v6}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    new-instance v5, Ljava/util/ArrayList;

    invoke-direct {v5}, Ljava/util/ArrayList;-><init>()V

    new-instance v8, Ljava/util/LinkedList;

    invoke-direct {v8}, Ljava/util/LinkedList;-><init>()V

    invoke-virtual {v5, v2}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

    invoke-virtual {v12, v3}, Ljava/util/LinkedList;->get(I)Ljava/lang/Object;

    move-result-object v2

    invoke-virtual {v8, v2}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    move-wide v6, v10

    goto :goto_4

    :cond_3
    add-long/2addr v6, v10

    invoke-virtual {v5, v2}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

    invoke-virtual {v12, v3}, Ljava/util/LinkedList;->get(I)Ljava/lang/Object;

    move-result-object v2

    invoke-virtual {v8, v2}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    goto :goto_4

    :cond_4
    invoke-virtual {v5}, Ljava/util/ArrayList;->isEmpty()Z

    move-result v2

    if-nez v2, :cond_5

    move-object/from16 v0, p0

    invoke-direct {v0, v5}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestBuilderPost(Ljava/util/ArrayList;)Lokhttp3/Request;

    move-result-object v2

    new-instance v3, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;

    const/4 v5, 0x0

    invoke-direct {v3, v5, v2, v8}, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;-><init>(ZLokhttp3/Request;Ljava/util/LinkedList;)V

    invoke-virtual {v13, v3}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    :cond_5
    move-object/from16 v0, p0

    iget-object v2, v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->bufferOption:Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;

    invoke-virtual {v2}, Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;->getCode()I

    move-result v2

    add-int/2addr v4, v2

    goto/16 :goto_2

    :cond_6
    return-object v13
.end method

.method public flush()V
    .locals 1

    new-instance v0, Lcom/snowplowanalytics/snowplow/tracker/Emitter$2;

    invoke-direct {v0, p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter$2;-><init>(Lcom/snowplowanalytics/snowplow/tracker/Emitter;)V

    invoke-static {v0}, Lcom/snowplowanalytics/snowplow/tracker/Executor;->execute(Ljava/lang/Runnable;)V

    return-void
.end method

.method public getBufferOption()Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->bufferOption:Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;

    return-object v0
.end method

.method public getByteLimitGet()J
    .locals 2

    iget-wide v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->byteLimitGet:J

    return-wide v0
.end method

.method public getByteLimitPost()J
    .locals 2

    iget-wide v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->byteLimitPost:J

    return-wide v0
.end method

.method public getEmitterStatus()Z
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v0

    return v0
.end method

.method public getEmitterTick()I
    .locals 1

    iget v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emitterTick:I

    return v0
.end method

.method public getEmitterUri()Ljava/lang/String;
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uriBuilder:Landroid/net/Uri$Builder;

    invoke-virtual {v0}, Landroid/net/Uri$Builder;->clearQuery()Landroid/net/Uri$Builder;

    move-result-object v0

    invoke-virtual {v0}, Landroid/net/Uri$Builder;->build()Landroid/net/Uri;

    move-result-object v0

    invoke-virtual {v0}, Landroid/net/Uri;->toString()Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public getEmptyLimit()I
    .locals 1

    iget v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->emptyLimit:I

    return v0
.end method

.method public getEventStore()Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->eventStore:Lcom/snowplowanalytics/snowplow/tracker/storage/EventStore;

    return-object v0
.end method

.method public getHttpMethod()Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->httpMethod:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

    return-object v0
.end method

.method public getRequestCallback()Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestCallback:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestCallback;

    return-object v0
.end method

.method public getRequestSecurity()Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestSecurity:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;

    return-object v0
.end method

.method public getSendLimit()I
    .locals 1

    iget v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->sendLimit:I

    return v0
.end method

.method protected performAsyncEmit(Ljava/util/LinkedList;)Ljava/util/LinkedList;
    .locals 10

    const/4 v9, 0x1

    const/4 v2, 0x0

    new-instance v4, Ljava/util/LinkedList;

    invoke-direct {v4}, Ljava/util/LinkedList;-><init>()V

    new-instance v5, Ljava/util/LinkedList;

    invoke-direct {v5}, Ljava/util/LinkedList;-><init>()V

    invoke-virtual {p1}, Ljava/util/LinkedList;->iterator()Ljava/util/Iterator;

    move-result-object v1

    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_0

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;->getRequest()Lokhttp3/Request;

    move-result-object v0

    invoke-direct {p0, v0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->getRequestCallable(Lokhttp3/Request;)Ljava/util/concurrent/Callable;

    move-result-object v0

    invoke-static {v0}, Lcom/snowplowanalytics/snowplow/tracker/Executor;->futureCallable(Ljava/util/concurrent/Callable;)Ljava/util/concurrent/Future;

    move-result-object v0

    invoke-virtual {v5, v0}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    goto :goto_0

    :cond_0
    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Request Futures: %s"

    new-array v3, v9, [Ljava/lang/Object;

    invoke-virtual {v5}, Ljava/util/LinkedList;->size()I

    move-result v6

    invoke-static {v6}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v6

    aput-object v6, v3, v2

    invoke-static {v0, v1, v3}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->d(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    move v1, v2

    :goto_1
    invoke-virtual {v5}, Ljava/util/LinkedList;->size()I

    move-result v0

    if-ge v1, v0, :cond_2

    const/4 v3, -0x1

    :try_start_0
    invoke-virtual {v5, v1}, Ljava/util/LinkedList;->get(I)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/concurrent/Future;

    const-wide/16 v6, 0x5

    sget-object v8, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;

    invoke-interface {v0, v6, v7, v8}, Ljava/util/concurrent/Future;->get(JLjava/util/concurrent/TimeUnit;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Integer;

    invoke-virtual {v0}, Ljava/lang/Integer;->intValue()I
    :try_end_0
    .catch Ljava/lang/InterruptedException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/util/concurrent/ExecutionException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljava/util/concurrent/TimeoutException; {:try_start_0 .. :try_end_0} :catch_2

    move-result v0

    move v3, v0

    :goto_2
    invoke-virtual {p1, v1}, Ljava/util/LinkedList;->get(I)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;->isOversize()Z

    move-result v0

    if-eqz v0, :cond_1

    new-instance v3, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;

    invoke-virtual {p1, v1}, Ljava/util/LinkedList;->get(I)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;->getEventIds()Ljava/util/LinkedList;

    move-result-object v0

    invoke-direct {v3, v9, v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;-><init>(ZLjava/util/LinkedList;)V

    invoke-virtual {v4, v3}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    :goto_3
    add-int/lit8 v0, v1, 0x1

    move v1, v0

    goto :goto_1

    :catch_0
    move-exception v0

    iget-object v6, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v7, "Request Future was interrupted: %s"

    new-array v8, v9, [Ljava/lang/Object;

    invoke-virtual {v0}, Ljava/lang/InterruptedException;->getMessage()Ljava/lang/String;

    move-result-object v0

    aput-object v0, v8, v2

    invoke-static {v6, v7, v8}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    goto :goto_2

    :catch_1
    move-exception v0

    iget-object v6, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v7, "Request Future failed: %s"

    new-array v8, v9, [Ljava/lang/Object;

    invoke-virtual {v0}, Ljava/util/concurrent/ExecutionException;->getMessage()Ljava/lang/String;

    move-result-object v0

    aput-object v0, v8, v2

    invoke-static {v6, v7, v8}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    goto :goto_2

    :catch_2
    move-exception v0

    iget-object v6, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v7, "Request Future had a timeout: %s"

    new-array v8, v9, [Ljava/lang/Object;

    invoke-virtual {v0}, Ljava/util/concurrent/TimeoutException;->getMessage()Ljava/lang/String;

    move-result-object v0

    aput-object v0, v8, v2

    invoke-static {v6, v7, v8}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->e(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    goto :goto_2

    :cond_1
    new-instance v6, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;

    invoke-direct {p0, v3}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isSuccessfulSend(I)Z

    move-result v3

    invoke-virtual {p1, v1}, Ljava/util/LinkedList;->get(I)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;

    invoke-virtual {v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/ReadyRequest;->getEventIds()Ljava/util/LinkedList;

    move-result-object v0

    invoke-direct {v6, v3, v0}, Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestResult;-><init>(ZLjava/util/LinkedList;)V

    invoke-virtual {v4, v6}, Ljava/util/LinkedList;->add(Ljava/lang/Object;)Z

    goto :goto_3

    :cond_2
    return-object v4
.end method

.method public setBufferOption(Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;)V
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v0

    if-nez v0, :cond_0

    iput-object p1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->bufferOption:Lcom/snowplowanalytics/snowplow/tracker/emitter/BufferOption;

    :cond_0
    return-void
.end method

.method public setEmitterUri(Ljava/lang/String;)V
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v0

    if-nez v0, :cond_0

    iput-object p1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->uri:Ljava/lang/String;

    invoke-direct {p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->buildEmitterUri()V

    :cond_0
    return-void
.end method

.method public setHttpMethod(Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;)V
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v0

    if-nez v0, :cond_0

    iput-object p1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->httpMethod:Lcom/snowplowanalytics/snowplow/tracker/emitter/HttpMethod;

    invoke-direct {p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->buildEmitterUri()V

    :cond_0
    return-void
.end method

.method public setRequestSecurity(Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;)V
    .locals 1

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v0

    if-nez v0, :cond_0

    iput-object p1, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->requestSecurity:Lcom/snowplowanalytics/snowplow/tracker/emitter/RequestSecurity;

    invoke-direct {p0}, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->buildEmitterUri()V

    :cond_0
    return-void
.end method

.method public shutdown()V
    .locals 4

    const/4 v3, 0x0

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->TAG:Ljava/lang/String;

    const-string v1, "Shutting down emitter."

    new-array v2, v3, [Ljava/lang/Object;

    invoke-static {v0, v1, v2}, Lcom/snowplowanalytics/snowplow/tracker/utils/Logger;->d(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

    iget-object v0, p0, Lcom/snowplowanalytics/snowplow/tracker/Emitter;->isRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 v1, 0x1

    invoke-virtual {v0, v1, v3}, Ljava/util/concurrent/atomic/AtomicBoolean;->compareAndSet(ZZ)Z

    invoke-static {}, Lcom/snowplowanalytics/snowplow/tracker/Executor;->shutdown()V

    return-void
.end method
